import cv2


pic=cv2.imread('东方白鹳.jpg')

print(pic.shape)
dest_shape=(222,222)


ratio=(pic.shape[0]/dest_shape[0],pic.shape[1]/dest_shape[1])


choose_ratio=min(ratio)

choose_idx=0 if ratio[0]<ratio[1] else 1


pic=cv2.resize(pic, (int(pic.shape[1]/ratio[choose_idx]),int(pic.shape[0]/ratio[choose_idx])))
# print(pic.shape)



if choose_idx==0:
    pic=pic[:,int((pic.shape[1]-pic.shape[0])/2):-int((pic.shape[1]-pic.shape[0])/2),:]
else:
    pic=pic[int((pic.shape[0]-pic.shape[1])/2):-int((pic.shape[0]-pic.shape[1])/2),:,:]

print(pic.shape)
cv2.imwrite('tt.jpg',pic)
# cv2.waitKey(0)


